package com.servlet.user;

import com.dao.UserDao;
import com.dao.UserInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "UserUpdateServlet",urlPatterns = "/UserUpdateServlet.filter")
public class UserUpdateServlet extends HttpServlet {
//    private String encoding;


    private UserDao userDao = new UserInfo();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("UserUpdateServlet");
        String u_id = request.getParameter("u_id");
        String u_name = request.getParameter("u_name");
        String u_pwd = request.getParameter("u_pwd");
        String u_age = request.getParameter("u_age");
        String u_sex = request.getParameter("u_sex");
        try {
            userDao.update(Integer.parseInt(u_id),u_name ,u_pwd , Integer.parseInt(u_age), Integer.parseInt(u_sex));
            response.sendRedirect(request.getContextPath()+"/UserSelectAllServlet.filter");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
